package com.wang.sort;

public class Demo10_DeleteGivenValue {
    public static class Node{
        public int value;
        public Node next;
            public Node(int data){
                value = data;
            }
    }
    public static Node removeValue(Node head,int num){
        while (head != null){
            if(head.value != num){
                break;
            }
            head = head.next;
        }
       //来到第一个不需要删除的位置
        Node pre = null;
        Node cur = null;
        while (cur != null){
            if(cur.value == num){
                pre.next = cur.next;
            }
            else {
                pre = cur;
            }
            cur = cur.next;
        }
        return head;
    }
}

